package com.xk.Colletcion.Map;

import com.xk.Colletcion.pojo.Student;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class mapTest {
    public static void main(String[] args) {
        Map<Integer, Student> studentMap=new HashMap<>();
        Student student1=new Student("timi",19,"男",101,1);
        Student student2=new Student("anni",20,"女",102,1);
        Student student3=new Student("lisha",21,"女",103,2);
        studentMap.put(1,student1);
        studentMap.put(2,student2);
        studentMap.put(3,student3);

        //换取key值输出
        for (Integer s:studentMap.keySet()){
            Student stu4=studentMap.get(s);
            System.out.println(stu4.toString());
        }
        System.out.println("=====================");
        //获取value值输出
        for (Student stu4:studentMap.values()){
            System.out.println(stu4.toString());
        }

        //entrySet的使用
        System.out.println("entrySet的使用:");
        Set<Map.Entry<Integer,Student>> entrySet=studentMap.entrySet();
        for (Map.Entry<Integer,Student> entry:entrySet){
            Integer s=entry.getKey();
            Student stu1=entry.getValue();
            System.out.println(s+","+stu1.getName()+","+stu1.getSex());
        }

        System.out.println("========================");
        //数据的删除
        System.out.println("数据的删除:");
        studentMap.remove(2,student2);
        System.out.println("已成功删除："+student2);
        System.out.println("删除后的数据为：");
      for (Student stu5:studentMap.values()){
          System.out.println(stu5+","+studentMap.keySet());
      }

      //信息的查找
        System.out.println("数据的查找:");
        System.out.println(studentMap.get(3)+","+studentMap.keySet());
    }
}
